package br.com.insight.consultoria.integracao.dao;

import java.util.List;

import org.springframework.dao.DataAccessException;

import br.com.insight.consultoria.entity.Area;
import br.com.insight.consultoria.entity.Tipo;
import br.com.insight.consultoria.erro.exception.InsightConstants;
import br.com.insight.consultoria.erro.exception.InsightDaoException;
import br.com.insight.consultoria.erro.exception.InsightException;
import br.com.insight.consultoria.erro.exception.SistemaException;
import br.com.insight.consultoria.integracao.dao.genericdao.GenericDAO;
import br.com.insight.consultoria.integracao.dao.interfacedao.TipoDAO;

public class TipoImpDAO extends GenericDAO implements TipoDAO{

	public Tipo getTipo(Long id) throws InsightException{
		
		try{
		
		return (Tipo) getEntityById(Tipo.class,id);
		
		}catch(DataAccessException sql){
			
			throw new InsightDaoException(InsightConstants.MENSAGEM_ERRO_ACESSO_BANCO,sql);
		
		}catch(Exception ex){
			
			throw new SistemaException(InsightConstants.MENSAGEM_ERRO_NAO_TRATADO,ex);
			
		}
	}
	
	@Override
	public List<Tipo> pesquisa(Area area) throws InsightException {
	
		List<Tipo> tipo=null;
		
		try{
		
			tipo=findFiltered(Tipo.class,"area",area);
	
		}catch(DataAccessException sql){
		
		throw new InsightDaoException(InsightConstants.MENSAGEM_ERRO_ACESSO_BANCO,sql);
	
	}catch(Exception ex){
		
		throw new SistemaException(InsightConstants.MENSAGEM_ERRO_NAO_TRATADO,ex);
		
	}
		
		return tipo;
	}
}
